import java.io.*;

public class CalendarEvent {
	private String eventName;
	private String startDate;
	private String endDate;
	private String startTime;
	private String endTime;
	private String timeZone;
	private String location;
	private String description;
	private String timeZoneNumber;
	private String coordinates;
	private String classification;
	private int    priority;
	private String recurrence;
	
	public CalendarEvent(){
		
	}
	//constructor
	public CalendarEvent(String name, String startDateInput, String endDateInput, String startTimeInput,
			String endTimeInput, String zone, String descriptionInput, String locationInput,
			String classificationInput, int priorityInput, String recurrenceInput, String cordInput){
			
		eventName      	   = name;
		startDate          = startDateInput;
		endDate            = endDateInput;
		startTime          = startTimeInput;
		endTime            = endTimeInput;
		description        = descriptionInput;
		location           = locationInput;
		coordinates        = cordInput;
		priority           = priorityInput;
		classification     = classificationInput;
		recurrence         = recurrenceInput;
		
		String temp        = new String(zone);
		String[] arrayTemp = temp.split("\\s+");
		timeZoneNumber     = arrayTemp[0].replaceAll("[):(]", "");
		timeZone           = arrayTemp[1];
		timeZone          += " Standard ";
		timeZone          += arrayTemp[2];
	}
	
	/**
	 * Writes out the calendar information to an .ics file, produces a readable .ics file assuming all of the fields have correct input
	 * Uses formatted to be similar to Microsoft OutLook
	 * ex. 1:00 pm is 1300, August 13, 2004 is  20140813
	 * 
	 */
	public void write(){
		try{
			 FileOutputStream fos = new FileOutputStream("test.ics");
			 Writer out = new OutputStreamWriter(fos);
			 out.write("BEGIN:VCALENDAR");
			 out.write("\r\nPRODID:-//Microsoft Corporation//Outlook 14.0 MIMEDIR//EN");
			 out.write("\r\nVERSION:2.0");
			 out.write("\r\nBEGIN:VTIMEZONE");
			 out.write("\r\nTZID:" + timeZone);
			 out.write("\r\nBEGIN:STANDARD");
			 out.write("\r\nDTSTART:16010101T000000");
			 out.write("\r\nTZOFFSETFROM:" + timeZoneNumber);
			 out.write("\r\nTZOFFSETTO:" + timeZoneNumber);
			 out.write("\r\nEND:STANDARD");
			 out.write("\r\nEND:VTIMEZONE");
			 out.write("\r\nBEGIN:VEVENT");
			 out.write("\r\nCLASS:" + classification);
			 out.write("\r\nDESCRIPTION:" + description);
			 out.write("\r\nDTEND;TZID=\"" + timeZone + "\":" + endDate + "T" + endTime + "00");
			 out.write("\r\nDTSTART;TZID=\"" + timeZone + "\":" + startDate + "T" + startTime + "00");
			 out.write("\r\nLOCATION:" + location);
			 out.write("\r\nGEO:" + coordinates);
			 out.write("\r\nPRIORITY:" + priority);
			 out.write(recurrence);
			 out.write("\r\nSUMMARY:" + eventName);
			 out.write("\r\nEND:VEVENT");
			 out.write("\r\nEND:VCALENDAR");
			 out.write("\r\n");
			 out.close();
			 
		}catch(IOException e){
			
		}
	}
	
}
